<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="分单状态" prop="workerOrderstatus">
        <el-select v-model="queryParams.workerOrderstatus" placeholder="请选择" clearable>
          <el-option v-for="dict in workerOrderstatusList" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="订单合同号" prop="contractCode">
        <el-input v-model="queryParams.contractCode" placeholder="请输入订单合同号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="产品名称" prop="productName">
        <el-input v-model="queryParams.productName" placeholder="请输入产品名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleWorkerOrder"
          v-hasPermi="['order:orderproduct:edit']">执行分单</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading"
              border style="width:100%;" :data="orderproductList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" :selectable="handleDisable">

      </el-table-column>
      <el-table-column label="订单合同号" align="center" prop="contractCode" />
      <el-table-column label="客户名称" align="center" prop="customName" />
      <el-table-column label="单据编号" align="center" prop="orderCode" />
      <el-table-column label="订单日期" align="center" prop="orderDate" width="100px">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.orderDate, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="产品名称" align="center" prop="productName" />
      <el-table-column label="产品编码" align="center" prop="productCode" />
      <el-table-column label="规格型号" align="center" prop="productStandard" width="120"/>
      <el-table-column label="产品单位" align="center" prop="productUnit" width="80px"/>
      <el-table-column label="产品数量" align="center" prop="productNum" width="80px"/>
      <el-table-column label="已分单数量" align="center" prop="workerOrdernum" width="90px"/>
      <el-table-column label="分单状态" align="center" prop="workerOrderstatus" width="80px">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.workerorder_status" :value="scope.row.workerOrderstatus" />
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <!-- 0:待分单,1:已分单,2:部分分单 -->
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" v-if="scope.row.workerOrderstatus != 0"
                     @click="splitInfo(scope.row)">分单详情</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" v-if="scope.row.workerOrderstatus != 0"
                     @click="splitCancel(scope.row)">取消分单</el-button>

          <el-button size="mini" type="text" icon="el-icon-edit" v-if="scope.row.workerOrderstatus == 0 || scope.row.workerOrderstatus == 2"
            @click="handleWorkerOrder(scope.row)" v-hasPermi="['order:orderproduct:edit']">执行分单</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改订单信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1300px" :close-on-click-modal ="false" append-to-body @close="close1">
      <el-form ref="form" :model="form" label-width="120px">
        <el-row :gutter="5">
          <el-col :span="8">
            <el-form-item label="订单合同号：" prop="contractCode">
               {{ form.contractCode }}
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="客户名称：" prop="customName">
               {{ form.customName }}
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="单据编号：" prop="orderCode">
               {{ form.orderCode }}
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="订单日期：" prop="orderDate">
               {{ form.orderDate }}
            </el-form-item>
          </el-col>
          <!--<el-col :span="8">
            <el-form-item label="创建日期：" prop="orderCreatetime">
               {{ form.sailDepart }}
            </el-form-item>
          </el-col>-->
          <el-col :span="8">
            <el-form-item label="销售部门：" prop="sailDepart">
               {{ form.sailDepart }}
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="物料编码：" prop="productCode">
              {{ form.productCode }}
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="物料名称：" prop="productName">
              {{ form.productName }}
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="规格型号：" prop="productStandard">
              {{ form.productStandard }}
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="订单数量：" prop="productNum">
              {{ form.productNum }}
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="产品单位：" prop="productUnit">
              {{ form.productUnit }}
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="订单备注" prop="orderRemark">
              {{ form.orderRemark }}
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-divider></el-divider>

      <el-table
        :data="bominfoList"
        style="width: 100%"
        row-key="id"
        border
        lazy
        :load="load"
        :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
          <el-table-column label="子项物料编码" align="center" prop="bomCode" />
          <el-table-column label="物料名称" align="center" prop="bomName">
          </el-table-column>
          <el-table-column label="分厂名称" align="center" prop="factoryName" />
          <el-table-column label="班组名称" align="center" prop="teamName" width="120px"/>
          <el-table-column label="物料属性" align="center" prop="bomAttribute" width="90px">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.bom_attribute" :value="scope.row.bomAttribute" />
            </template>
          </el-table-column>
          <el-table-column label="订单数量" align="center" prop="productNum" width="90px">
          </el-table-column>
          <el-table-column label="分单数量" align="center" prop="workerOrdernum" width="90px"/>
          <el-table-column label="库存情况" align="center" prop="storeStatus" width="120px">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.store_status" :value="scope.row.storeStatus" />
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width" prop="methodNum" width="100px">
            <template slot-scope="scope">
              <el-select v-model="scope.row.methodNum"
                v-if="scope.row.storeStatus == 1 && (scope.row.bomAttribute==2)"  placeholder="请选择">
                <el-option
                  v-for="item in statusOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width" prop="methodNum" width="100px">
            <template slot-scope="scope">
              <el-button size="mini" type="text" icon="el-icon-edit" v-if="scope.row.bomAttribute==2"
              @click="adjustWorkerOrder(scope.row)" v-hasPermi="['order:orderproduct:edit']">调整分单</el-button>
            </template>
          </el-table-column>
      </el-table>
      <!--
      <el-table v-loading="loading" :data="bominfoList" @selection-change="handleSelectionChange1">

        <el-table-column label="子项物料编码" align="center" prop="bomCode" />
        <el-table-column label="物料名称" align="center" prop="bomName">
        </el-table-column>

        <el-table-column label="订单数量" align="center" prop="productNum">
        </el-table-column>
        <el-table-column label="分单数量" align="center" prop="workerOrdernum" />
        <el-table-column label="分厂名称" align="center" prop="factoryName" />
        <el-table-column label="班组名称" align="center" prop="teamName" />
        <el-table-column label="库存情况" align="center" prop="storeStatus" >
          <template slot-scope="scope">
            <dict-tag :options="dict.type.store_status" :value="scope.row.storeStatus" />
          </template>
        </el-table-column>
        <el-table-column label="物料属性" align="center" prop="bomAttribute">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.bom_attribute" :value="scope.row.bomAttribute" />
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" prop="methodNum">
          <template slot-scope="scope">
            <el-select v-model="scope.row.methodNum"
              v-if="scope.row.storeStatus == 1 && (scope.row.bomAttribute==2)"  placeholder="请选择">
              <el-option
                v-for="item in statusOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" prop="methodNum">
          <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-edit" v-if="(scope.row.storeStatus == 1 || scope.row.storeStatus == 3 )&& (scope.row.bomAttribute==2)"
             @click="adjustWorkerOrder(scope.row)" v-hasPermi="['order:orderproduct:edit']">调整分单</el-button>
          </template>
        </el-table-column>
      </el-table>-->
      <div slot="footer" class="dialog-footer" style="display: flex;justify-content: center;">
        <el-button type="primary" @click="syncSingleBom" style="display: flex; justify-content: center">同步BOM</el-button>
        <el-button type="primary" @click="submitWorkerOrder" style="display: flex; justify-content: center">提交分单</el-button>
      </div>
    </el-dialog>

    <!-- 分单提交对话框 -->
    <el-dialog :title="title" :visible.sync="workeropen" width="400px" append-to-body>
      <template>
        <div class="ceshi-content">
            <div class="check_item_block">
              <el-select v-model="formad.factoryId" placeholder="请选择分厂" @change="factorychange($event, ix)">
                <el-option v-for="item in factoryList" :key="item.deptId" :label="item.deptName" :value="item.deptId">
                </el-option>
              </el-select>
            </div>
            <div class="check_item_block">
              <el-select v-model="formad.teamId" placeholder="请选择班组">
                <el-option v-for="item in teamList" :key="item.deptId" :label="item.deptName" :value="item.deptId">
                </el-option>
              </el-select>
            </div>
        </div>
      </template>
      <div slot="footer" class="dialog-footer" style="display: flex;justify-content: center;">
        <el-button type="primary" @click="submitAdjust" style="display: flex; justify-content: center">确定</el-button>
      </div>
    </el-dialog>

    <!-- 分单提交对话框 -->
    <el-dialog :title="title" :visible.sync="workeropen1" width="800px" append-to-body>
      <template>
        <div class="ceshi-content">
          <div class="check_btn">
            <!-- <div>
                <el-button type="primary" @click="addCheck">增加</el-button>
              </div>
              <div>
                <el-button type="success" @click="subCheck">提交</el-button>
              </div>-->
          </div>
          <div class="check_item" v-for="(item, ix) in bominfoList" :key="item.id">
            <div class="check_item_block">
              <el-select v-model="item.vModel" placeholder="请选择分厂" @change="checkFen($event, ix)">
                <el-option v-for="item in factoryList" :key="item.deptId" :label="item.deptName" :value="item.deptId">
                </el-option>
              </el-select>
            </div>
            <div class="check_item_block">
              <el-select v-model="item.vModel2" placeholder="请选择班组">
                <el-option v-for="item in item.childList" :key="item.deptId" :label="item.deptName" :value="item.deptId">
                </el-option>
              </el-select>
            </div>
            <div class="check_item_block">

              <!-- 数量统一显示 -->
              <el-input-number v-model="productNum2" :min="0" :max="form.productNum" label="请揄入数量(数量约束)"
                :default="productNum2"></el-input-number>

              <!-- 数量每项显示 :max="item.vModel3"
              <el-input-number v-model="item.vModel3" :min="0"  label="请揄入数量(数量约束)"
                :default="item.vModel3"></el-input-number> -->
            </div>

            <!--<el-button type="info" style="margin-left: 30px" @click="delCheck(ix)">移除</el-button>-->
          </div>
        </div>
      </template>
      <div slot="footer" class="dialog-footer" style="display: flex;justify-content: center;">
        <el-button type="primary" @click="submitWorkerOrder" style="display: flex; justify-content: center">确定</el-button>
      </div>
    </el-dialog>

     <!-- 分单详情信息对话框 -->
     <el-dialog :title="title" :visible.sync="detailopen" width="1000px" :close-on-click-modal ="false" append-to-body>

      <el-table v-loading="loading" :data="workOrderDetailList">
        <el-table-column label="子项物料编码" align="center" prop="bomCode" />
        <el-table-column label="物料名称" align="center" prop="bomName">
        </el-table-column>
        <el-table-column label="订单数量" align="center" prop="productNum">
        </el-table-column>
        <el-table-column label="分单数量" align="center" prop="workerOrdernum" />
        <el-table-column label="分厂名称" align="center" prop="factoryName" />
        <el-table-column label="班组名称" align="center" prop="teamName" />
        <el-table-column label="库存情况" align="center" prop="storeStatus" >
          <template slot-scope="scope">
            <dict-tag :options="dict.type.store_status" :value="scope.row.storeStatus" />
          </template>
        </el-table-column>
        <el-table-column label="物料属性" align="center" prop="bomAttribute">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.bom_attribute" :value="scope.row.bomAttribute" />
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>

  </div>
</template>

<script>
import {
  listSeparateOrderproduct,
  getWorkerOrderproduct,
  listProductbom,updateOrderproduct
} from "@/api/sm/order/orderproduct";
import { listDept, getDept } from "@/api/system/dept";
import { submitWorkerOrder,checkProductNumStore,splitCancel,listWorkorder } from "@/api/sm/order/workorder";
import { addOutbound } from "@/api/sm/order/outbound";
import { listChildren,syncSingleBom } from "@/api/sm/basic/bominfo";

export default {
  name: "Orderinfo",
  dicts: ["order_status", "workerorder_status","store_status","bom_attribute"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      codes: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 非多个禁用
      multiple1: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      plantotal: 0,
      // 订单信息表格数据
      orderproductList: [],
      bominfoList: [],
      factoryList: [],
      teamList: [],
      workOrderDetailList: [],
      statusOptions: [
        {
          label: "出库",
          value: 2
        },
        {
          label: "继续分单",
          value: 1,
        }
      ],
      workerOrderstatusList: [
        {
          label: "待分单",
          value: 0,
        },
        {
          label: "部分分单",
          value: 2,
        },
        {
          label: "已分单",
          value: 1,
        },
      ],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      bomopen: false,
      workeropen: false,
      workeropen1: false,
      detailopen: false,
      // 同步时间时间范围
      daterangeOrderDate: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        contractCode: null,
        productName: null,
        orderDate: null,
        workerOrderstatus: 0,
      },
      // 查询参数
      queryParams1: {
        pageNum: 1,
        pageSize: 100,
        productId: null
      },

      productNum2: 0,
      // 表单参数
      form: {
        productNum: null,
        productId: null,
      },
      // 表单参数
      form1: {
        orderIds: null,
        orderPlanList: null,
      },
      productform:{
        id: null,
        orderCode: null,
        productCode: null,
        productStatus: null,
        workerOrderstatus: null
      },
      outform: {
        productType: 1,
        orderCode: null,
        productId: null,
        productCode: null,
        productName: null,
        factoryName: null,
        factoryId: null,
        outNum: null,
      },
      formad : {
        factoryId: null,
        teamId: null,
        id: null,
      },
      // 表单校验
      rules: {
        planStartDate: [
          { required: true, message: "排产截止时间不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
    this.getFactoryList();
  },
  methods: {
    //显示分单详情
    splitInfo(row){
      this.loading = true;
      this.queryParams1.productId = row.id;
      listWorkorder(this.queryParams1).then((response) => {
        this.workOrderDetailList = response.rows;
        this.detailopen = true;
        this.loading = false;
      });
    },
    load(tree, treeNode, resolve) {
      listChildren({"parentBomCode":tree.bomCode,"productId":this.form.productId}).then((res) => {   //getChildMenu是我们自己的调用后台的封装
          resolve(                            //resolve是组件的
              res.data  //根据自己的格式,将查到的子菜单数组填充
          )
      })
    },
    /** 同步bom */
    syncSingleBom(row) {
      this.loading = true;
      syncSingleBom(this.form.productId,this.form.productCode).then((response) => {
        this.$modal.msgSuccess("同步成功");
        this.open = false;
        this.loading = false;
      });
    },
    submitAdjust(){
      this.bominfoList.map((item, index) => {
        if (item.id == this.formad.id){
          this.workeropen=false;
          item.factoryId=this.formad.factoryId;
          item.teamId=this.formad.teamId;
          this.factoryList.map((item1, index) => {
            if (item1.deptId == this.formad.factoryId){
              item.factoryName=item1.deptName;
            }
           })
          this.teamList.map((item2, index) => {
            if (item2.deptId == this.formad.teamId){
              item.teamName=item2.deptName;
            }
          })
        }
      });
     },
     /** 调整 */
     adjustWorkerOrder(row) {
      this.workeropen=true;
      this.formad.id=row.id;
      this.formad.factoryId=row.factoryId;
      this.getTeamList(row.factoryId);
      this.formad.teamId=row.teamId;
      //this.reset();
      //const id = row.id || this.ids

    },
    handleDisable(row, index) {

      if (row.workerOrderstatus == '1') {
        return false
      } else {
        return true
      }
    },
    // 根据分厂id返回组数据集
    async childList(id) {
      let temRes = await listDept({ level: 3, delFlag: 0, parentId: id });
      return temRes.data;
    },
    // 分厂下拉回调
    checkFen(eve, index) {
      listDept({ level: 3, delFlag: 0, parentId: eve }).then((res) => {
        // 初始化每一项的"组"列表值
        this.$set(this.bominfoList[index], "childList", res.data);
      });

      this.$set(this.bominfoList[index], "vModel2", "");
    },
    close1() {
      this.loading = false;
    },

    // 初始每一项的数据组
    fn_groupList() {

      this.bominfoList.forEach((item, ix) => {
        // 初始化每一项的分厂id
        this.$set(this.bominfoList[ix], "vModel", item.factoryId);

        // 初始化每一项的"组"值
        this.$set(this.bominfoList[ix], "vModel2", item.teamId);

        // 初始化每一项的"数量"值this.form.productNum
        this.$set(this.bominfoList[ix], "vModel3", item.workerOrdernum);



        listDept({ level: 3, delFlag: 0, parentId: item.factoryId }).then(
          (res) => {
            // 初始化每一项的"组"列表值
            this.$set(this.bominfoList[ix], "childList", res.data);
          }
        );
      });
    },
    // 增加项
    addCheck() {
      this.bominfoList.push({ id: new Date().getTime(), factoryId: "" });
    },

    // 删除选中项
    delCheck(index) {
      this.bominfoList.splice(index, 1);
    },
    factorychange(){
      this.formad.teamId = null;
      this.getTeamList(this.formad.factoryId);
    },
    getFactoryList() {
      listDept({ level: 2, delFlag: 0 }).then((response) => {
        this.factoryList = response.data;
      });
    },
    getTeamList(factoryId) {
      listDept({ level: 3, delFlag: 0, parentId: factoryId }).then(
        (response) => {
          this.teamList = response.data;
        }
      );
    },
    /** 查询订单信息列表 */
    getList() {
      this.loading = true;
      listSeparateOrderproduct(this.queryParams).then((response) => {
        this.orderproductList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        contractCode: null,
        customName: null,
        orderDate: null,
        orderRemark: null,
        orderCode: null,
        sailDepart: null,
        productCode: null,
        productName: null,
        productStandard: null,
        productNum: null,
        productUnit: null

      };
      this.resetForm("form");
    },
    // 表单重置
    resetout() {
      this.outform = {
        productType: 1,
        orderCode: null,
        productId: null,
        productCode: null,
        productName: null,
        factoryName: null,
        factoryId: null,
        outNum: null,
      };
      this.resetForm("outform");
    },
    // 表单重置
    resetproduct() {
      this.productform = {
        id: null,
        orderCode: null,
        productCode: null,
        productStatus: null,
        workerOrderstatus: null
      };
      this.resetForm("productform");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeOrderDate = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.codes = selection.map((item) => item.productCode);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },

    // 多选框选中数据
    handleSelectionChange1(selection) {
      this.multiple1 = !selection.length;
    },
    splitCancel(row) {
      this.loading = true;
      const that = this;
      this.$modal.confirm(`确认要取消 \n [${row.orderCode} / ${row.productName}] \n分单订单吗？`).then(function() {
        splitCancel({
          "orderCode": row.orderCode,
          "productId": row.id,
          "productCode": row.productCode
        }).then(response => {
          that.loading = false;
          that.$modal.msgSuccess("取消成功");
          that.getList();
        }).catch(() => {});
      }).then(() => {
      }).catch(() => {
        this.loading = false;
      });
    },
    handleWorkerOrder(row) {
      this.loading = true;
      this.reset();

      this.bominfoList=null;
      const id = row.id || this.ids;
      checkProductNumStore(id).then((response) => {
        if(response.data){
          let that=this;
          this.$modal.confirm('库存已经满足订单数量,确认是继续分单,取消还是库存直接出货?').then(function() {
            getWorkerOrderproduct(id).then((response) => {
              that.open = true;
              that.title = "执行分单";

              that.form = response.data;
              that.productNum2 = response.data.productNum-response.data.workerOrdernum;
              that.form.productId = response.data.id;
            });
          }).then(() => {

          }).catch(() => {
            this.resetout();
            this.resetproduct();
            this.outform.productType=1;
            this.outform.orderCode=row.orderCode;
            this.outform.productId=row.id;
            addOutbound(this.outform).then(response => {
              this.productform.id=row.id;
              this.productform.workerOrderstatus=3;
              this.productform.productStatus=1;
              updateOrderproduct(this.productform).then(response => {
                this.$modal.msgSuccess("出库成功");
                this.open = false;
                this.getList();
              });
            });
          });
          listProductbom(id).then((response2) => {
              that.bominfoList = response2.data;
               that.loading = false;
            });
        }else{

          getWorkerOrderproduct(id).then((response) => {
            this.open = true;
            this.title = "执行分单";
            this.form = response.data;
            this.productNum2 = response.data.productNum-response.data.workerOrdernum;
            this.form.productId = response.data.id;
          });

          listProductbom(id).then((response) => {
              this.bominfoList = response.data;
              this.loading = false;
          });
        }

      }).catch(()=>{
        listProductbom(id).then((response) => {
          this.bominfoList = response.data;
          this.loading = false;
        });
        this.loading = false;
      });

    },

    /**执行分单操作 */
    handleWorkerOrder1(row) {
      this.loading = true;
      const id = row.id || this.ids;
      let checkStore=false;
      checkProductNumStore(id).then((response) => {
        alert("1111111"+response.data);
        checkStore = response.data;
        this.productNum2 = response.data.productNum-response.data.workerOrdernum;
        this.form.productId = response.data.id;
      });
      console.log("checkStore========="+checkStore);
      if(checkStore){
        alert(checkStore);
        this.$modal.confirm('库存已经满足订单数量,点击确认：继续分单,点击取消则：库存直接出货?').then(function() {
          getWorkerOrderproduct(id).then((response) => {
            this.open = true;
            this.title = "执行分单";
            this.loading = false;
            this.form = response.data;
            this.productNum2 = response.data.productNum-response.data.workerOrdernum;
            this.form.productId = response.data.id;
          });

          listProductbom(id).then((response2) => {
              this.bominfoList = response2.data;
          });
          }).then(() => {

          }).catch(() => {

          });

      }else{
        alert(2222);
        getWorkerOrderproduct(id).then((response) => {
            this.open = true;
            this.title = "执行分单";
            this.loading = false;
            this.form = response.data;
            this.productNum2 = response.data.productNum-response.data.workerOrdernum;
            this.form.productId = response.data.id;
        });

        listProductbom(id).then((response) => {
            this.bominfoList = response.data;
        });
      }
    },

    excuteWorderOrder() {
      this.workeropen = true;
      this.fn_groupList();
    },

    submitWorkerOrder() {

      let paramMap = {
        orderCode: this.form.orderCode,
        productId: this.form.productId,
        productNum: this.form.productNum,
        contractCode: this.form.contractCode,
        bomSubmitVOList: this.bominfoList,
      }

      this.bominfoList.map((item, index) => {
        if (item.factoryId == null || item.teamId==null) {
          alert("该工单没有分配分厂或者班组");
          throw new Error("break");
        }
      });

      submitWorkerOrder(paramMap).then((response) => {
        this.$modal.msgSuccess("提交分单成功");
        this.workeropen = false;
        this.open = false;
        this.getList();
      });
      },
    },
  }
</script>



<style scoped lang="scss">
.ceshi-content {
  .check_btn {
    display: flex;

    div {
      margin-right: 30px;
    }
  }

  .check_item {
    display: flex;
    margin-top: 30px;
  }
}
</style>
